package controllers;

import java.util.List;

import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
import unq.model.Juego;
import unq.model.Pais;
import views.html.index;

import com.fasterxml.jackson.databind.JsonNode;

import java.util.Collection;

import appmodel.play.AppModelPPlay;
import appmodel.play.AppModelPais;
import appmodel.play.Orden;
import appmodel.play.Viaje;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import play.*;
import play.libs.Json;
import play.mvc.*;
import views.html.*;

public class Application extends Controller {

	public static Result index() {

		return ok(index.render("Your new application is ready."));
		
	}

	public static Result initialize() {
		response().setContentType("application/json");
		
		JsonNode json = Json.toJson(new ModeloDelJuegoDTO((AppModelPPlay.getInstance()).inicializar()));
		return ok(json);
	}
	

	public static Result emitirOrden() {

		JsonNode node = request().body().asJson();
		Orden pedidoDeOrdenDeArresto = Json.fromJson(node, Orden.class);
       		
		pedidoDeOrdenDeArresto = AppModelPPlay.getInstance().emitirOrden(pedidoDeOrdenDeArresto.getNombre(),pedidoDeOrdenDeArresto.getID());

		ObjectNode result = Json.newObject();
		result.put("ordenDeArresto", pedidoDeOrdenDeArresto.getNombre());
		return ok(result);

	}

	public static Result viajar() {

		JsonNode node = request().body().asJson();
		Viaje viaje = Json.fromJson(node, Viaje.class);
       
		  ObjectNode result = Json.newObject();
//        app.setIdDelJuego(0);
//        viaje.setIdDelJuego(0);
		Viaje v = AppModelPPlay.getInstance().viajar(viaje);
		
		JsonNode json = Json.toJson(new ModeloDelJuegoDTO (v, AppModelPPlay.getInstance()));
        
		result.put("viajar", json);
		
		return ok(result);
	}
	
	public static Result actualizar() {
		response().setContentType("application/json");
		
		JsonNode json = Json.toJson(new ModeloDelJuegoDTO(AppModelPPlay.getInstance()));
		return ok(json);
	}

	
}